package net.caixiaomi.info.Lottery.adapter;

import android.text.Html;
import android.widget.TextView;

import net.caixiaomi.info.Lottery.model.BallLeaveEntity;
import net.caixiaomi.info.Lottery.model.TrendHotColdEntity;
import net.caixiaomi.info.R;
import net.caixiaomi.info.base.quickadapter.BaseMultiItemQuickAdapter;
import net.caixiaomi.info.base.quickadapter.BaseViewHolder;
import net.caixiaomi.info.base.quickadapter.entity.MultiItemEntity;
import net.caixiaomi.info.util.Constants;

import java.util.List;

/**
 * Created by suntian on 2018/8/17.
 */

public class TrendAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity,BaseViewHolder> {
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public TrendAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(Constants.ITEM_TREND_PRIZE, R.layout.trend_prize_layout);
        addItemType(Constants.ITEM_TREND_HEAT, R.layout.trend_heat_layout);
    }

    @Override
    protected void convert(BaseViewHolder helper, MultiItemEntity item) {
        try {
            switch (item.getItemType()) {
                case Constants.ITEM_TREND_PRIZE:
                    bindPrizeView(helper, item);
                    break;
                case Constants.ITEM_TREND_HEAT:
                    bindHeatView(helper, item);
                    break;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private int mType;

    public void setType(int type){
        mType=type;
    }

    private void bindPrizeView(BaseViewHolder helper, MultiItemEntity item){
        BallLeaveEntity entity= (BallLeaveEntity) item;
        helper.setText(R.id.trend_prize_name_tv,entity.getTermNum());
        TextView numTv=helper.getView(R.id.trend_prize_num_tv);
        String redNum="";
        String blueNum="";
        for(int i=0;i<5;i++){
            redNum=redNum+"  "+entity.getNumList().get(i);
        }
        for(int i=5;i<7;i++){
            blueNum=blueNum+"  "+entity.getNumList().get(i);
        }
        String numDes="<html><body><font color='red'>"+redNum+"</font><font color='blue'>"+blueNum+"</font></body></html>";
        numTv.setText(Html.fromHtml(numDes));
    }

    private void bindHeatView(BaseViewHolder helper, MultiItemEntity item){
        TrendHotColdEntity entity= (TrendHotColdEntity) item;
        helper.setText(R.id.trend_heat_num,entity.getNum()+"");
        helper.setText(R.id.trend_heat_num30,entity.getCountA()+"");
        helper.setText(R.id.trend_heat_num50,entity.getCountB()+"");
        helper.setText(R.id.trend_heat_num100,entity.getCountC()+"");
        helper.setText(R.id.trend_heat_leave,entity.getDrop()+"");
        if(mType==3){
            helper.setTextColor(R.id.trend_heat_num,mContext.getResources().getColor(R.color.red));
        }else{
            helper.setTextColor(R.id.trend_heat_num,mContext.getResources().getColor(R.color.blue));
        }
    }
}
